<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="__STATIC__/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">朋友圈</a>
        <a>
          <cite>分类</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>
<div class="x-body">
    <input type="hidden" name="id" value="{$id}" id="sf_id">
    <input type="hidden" name="bfr_id" value="{$bfr_id}" id="bfr_id">
    <table class="layui-hide" id="test" lay-filter="test"></table>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckData">
                <i class="layui-icon layui-icon-delete"></i>批量删除
            </button>
            <!--<button class="layui-btn layui-btn-sm" lay-event="add">-->
                <!--<i class="layui-icon layui-icon-delete"></i>添加-->
            <!--</button>-->
        </div>
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="reply">二级回复</a>
        <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
    </script>
</div>

<script>
    layui.use('table', function(){
        var table = layui.table;
        var sf_id=$("#sf_id").val();
        var bfr_id=$("#bfr_id").val();
        table.render({
            elem: '#test'
            ,url:'{:url("profess/forumListReplyAjax")}'
            ,where:{pf_id:sf_id,bfr_id:bfr_id}
            ,toolbar: '#toolbarDemo'
            ,title: '话题回复'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'bfr_id', title:'ID', width:80, fixed: 'left', unresize: true}
                ,{field:'user_id', title:'回复者ID'}
                ,{field:'nick_name', title:'回复者昵称'}
                ,{field:'image', title:'回复者头像',templet:function (d) {
                    return '<img src="'+d.image+'" alt="..." width="50px" height="50px" >';
                }}
                ,{field:'bfr_title', title:'回复内容'}
                ,{field:'bfr_createtime', title:'回复时间'}
                ,{field:'bfr_clickzan_number', title:'获赞数量'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var event = checkStatus.data;
                    var ids = tableCheckedAllOnly(event);
                    layer.confirm('真的删除行么', function(index){
                        $.post('{:url("profess/forumReplyDel")}',{bfr_id:ids},function (res) {
                            if (res.msg=='success'){
                                layer.msg(res.msg,{icon:6,time:1000},function () {
                                    table.reload('test');
                                });
                            } else {
                                layer.msg(res.msg,{icon:5,time:3000});
                            }
                        });
                    });
                    break;
                case 'add':
                    x_admin_show('添加分类','{:url("profess/professClassifyAdd")}');
                    break;
            }
        });


        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){$.post('{:url("profess/forumReplyDel")}',{bfr_id:data.bfr_id},function (res) {
                        if (res.code){
                            layer.msg(res.msg,{icon:6,time:1000},function () {
                                table.reload('test');
                            });
                        } else {
                            layer.msg(res.msg,{icon:5,time:3000});
                        }
                    });
                });
            } else if(obj.event === 'edit'){
                x_admin_show('修改','{:url("profess/forumReplyEdit")}?bfr_id='+data.bfr_id);
            }else if(obj.event === 'reply'){
                x_admin_show('回复','{:url("profess/forumListReply")}?id='+data.pf_id+'&bfr_id='+data.bfr_id);
            }
        });
    });
    function tableCheckedAllOnly(data){
        var arr = [];
        for (var i=0; i < data.length ;i++){
            arr.push(data[i].bfr_id);
        }
        return arr;
    }
</script>
</body>

</html>